package com.shj.em.biz.sys.service;

import com.shj.em.biz.sys.entity.RankAmount;
import com.shj.em.biz.sys.mapper.RankAmountMapper;
import com.shj.em.biz.sys.service.RankAmountService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import com.baomidou.mybatisplus.plugins.Page;

import java.util.*;

import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;


/**
 * 等级金额表 服务实现类
 *
 * @author Shen Huang Jian
 * @since 2018-08-08
 */
@Service
@Transactional
public class RankAmountServiceImpl extends ServiceImpl<RankAmountMapper, RankAmount> implements RankAmountService {

    @Autowired
    RankAmountMapper rankamountMapper;

    /**
     * 所有的现在生效的。 del_flag = 0
     * @return
     */
    public List<RankAmount> findAllRankAmounts(){
        return rankamountMapper.findAllRankAmounts();
    }

    /**
     * 所有的，包括 del_flag = 1
     * @param year
     * @return
     */
    public Map<String, List<RankAmount>> findAllRankAmountsInYear(int year){
        //String yearBegin = year + "-01-01";
        //String yearEnd = year + "-12-31";
        List<RankAmount> list = rankamountMapper.findAllRankAmountsInYear();
        Map<String, List<RankAmount>> map = new HashMap<>();

        for(RankAmount ra : list){
            if(!map.containsKey(ra.getRank())){
                map.put(ra.getRank(), new ArrayList<>());
            }
            map.get(ra.getRank()).add(ra);
        }
        return map;
    }
}
